package com.jkkc.lib.base.dialog

import android.content.Context
import com.blankj.utilcode.util.ThreadUtils

/**
 * Author:LiXian
 * <p>
 * Desc:提示框
 * Version:1.0
 * date 2023/2/24 13:11
 */
class MiniDialog(var mContext: Context, var isOutTimeCancel: Boolean = true, var outTime: Int = 10) {

    private var mDialog: MyDialog? = null

    fun showDialog(title: String? = "") {
        if (mDialog == null) {
            mDialog = MyDialog(mContext, title)
        }
        mDialog?.takeIf { !it.isLoading }?.show()
        mDialog?.updateMessage(title)
        if (isOutTimeCancel) {
            ThreadUtils.runOnUiThreadDelayed({
                mDialog?.let { dismissDialog() }
            }, outTime * 1000L)
        }
    }

    fun dismissDialog() {
        mDialog?.let { if (it.isLoading) it.dismiss() }
        mDialog = null
    }

    companion object {
        @JvmStatic
        fun getMiniDialog(mContext: Context, isOutTimeCancel: Boolean = true, outTime: Int = 10) =
                MiniDialog(mContext, isOutTimeCancel, outTime)
    }
}